﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Example1.Model
{
    class Model
    {

        Player m_player = new Player();
        const float m_bottomOfLevel = 0;

        internal bool CanJump()
        {
            //player can jump if position on the bottom of the level
            if (m_player.GetPosition().Y > m_bottomOfLevel)
            {
                return false;
            }
            return true;
        }

        internal void DoJump()
        {
            m_player.DoJump();
        }

        internal void Update(float a_elapsedTime, IObserver a_observer)
        {
            //get a new position for the player
            m_player.Update(a_elapsedTime);


            //check level constraint
            if (m_player.GetPosition().Y < m_bottomOfLevel)
            {
                //player has penetrated floor so move him up
                m_player.SetPosition( m_player.GetPosition().X, m_bottomOfLevel);

                if (m_player.GetSpeed().Y < -1)
                {
                    a_observer.LandOnFloor();
                }

                //slow down player
                m_player.SetSpeed(m_player.GetSpeed().X, 0);
            }
        }


        internal Microsoft.Xna.Framework.Vector2 GetPlayerPosition()
        {
            return m_player.GetPosition();
        }
    }
}
